/**
 *
 */
package com.zhengtoon.mctoon.conv.service.sdzc;

import com.zhengtoon.mctoon.conv.bean.sdzc.LetterAttachment;
import com.zhengtoon.mctoon.conv.dao.sdzc.LetterAttachmentMapper;
import com.zhengtoon.mctoon.conv.dto.param.UploadInputParam;
import com.zhengtoon.mctoon.conv.dto.param.UploadOutputResult;
import com.zhengtoon.mctoon.conv.service.sdzc.LetterAttachmentService;
import com.zhengtoon.mctoon.conv.utils.CloudAppUtils;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * 信件附件 impl实现
 *
 * @author 刘振华
 * @since 2017-04-12
 * Copyright: Copyright (c) 2017
 * Company:北京政务通科技有限公司
 */
@Service
public class LetterAttachmentServiceImpl implements LetterAttachmentService {

    private static Logger log = LoggerFactory.getLogger(LetterAttachmentServiceImpl.class);

    @Autowired
    private LetterAttachmentMapper ghlLetterAttachmentMapper;


    @Override
    public LetterAttachment selectSingle(String ghlLetterAttachmentId, String ghlLetterAttachmentUrl, String createTime, String updateTime) {
        return ghlLetterAttachmentMapper.selectSingle(ghlLetterAttachmentId, ghlLetterAttachmentUrl, createTime, updateTime);
    }

    /**
     * 批量上传信件附件 144637
     *
     * @param inputParamList
     * @return
     */
    @Override
    public List<UploadOutputResult> uploadAttachment(List<UploadInputParam> inputParamList) {

        List<UploadOutputResult> resultList = new ArrayList<>();

        // 遍历上传
        for (UploadInputParam input : inputParamList) {

            UploadOutputResult outputResult = new UploadOutputResult();

            // 获得公有云url
            String url = CloudAppUtils.getPublicUrl(input);

            outputResult.setFileUrl(url);

            resultList.add(outputResult);
        }

        return resultList;
    }


}